﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace MVVM_Wrapper_Test {
   /// <summary>
   /// Interaction logic for Window1.xaml
   /// </summary>
   public partial class Window1 : Window {

      public ObservableCollection<Person> PersonCollection { get; private set; }

      public PersonViewModelCollection PersonViewModelCollection { get; private set; }

      public Window1() {

         this.PersonCollection = new ObservableCollection<Person>();
         //add some people
         this.PersonCollection.Add(new Person { Name = "Billy", Age = 23 });
         this.PersonCollection.Add(new Person { Name = "James", Age = 10 });
         this.PersonCollection.Add(new Person { Name = "Jill", Age = 16 });
         this.PersonCollection.Add(new Person { Name = "Aran", Age = 34 });
         this.PersonCollection.Add(new Person { Name = "Dave", Age = 56 });

         //wrap the collection and the items in it
         this.PersonViewModelCollection = new PersonViewModelCollection(this.PersonCollection);

         InitializeComponent();
      }

      private void addPersonToUnderlyingCollection_Click(object sender, RoutedEventArgs e) {
         this.PersonCollection.Add(new Person { Name = DateTime.Now.ToShortTimeString(), Age = 10 });
      }

      private void removePersonFromUnderlyingCollection_Click(object sender, RoutedEventArgs e) {
         if (this.PersonCollection.Count > 0) {
            this.PersonCollection.RemoveAt(0);
         }
      }
   }
}
